package com.yunkaweilai.android.view.dialog.guadan;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.utils.CornerUtils;
import com.flyco.dialog.widget.base.BaseDialog;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.interfaces.SimpleInterface;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.Utils;

/**
 * 删除图片
 * Created by Administrator on 2017/6/27.
 */

public class GuadanLableDelDialog extends BaseDialog<GuadanLableDelDialog> {

    TextView idTvDel;
    TextView idTvClose;
    private Context context;
    private ImageView idImgClose;
    private String type;
    private TextView idEdtTypeName;
    private SimpleInterface simpleInterface;
    private String id;
    public GuadanLableDelDialog(Context context, SimpleInterface simpleInterface,String id) {
        super(context);
        this.context = context;
        this.simpleInterface = simpleInterface;
        this.id = id;

    }

    @Override
    public View onCreateView() {
        widthScale(0);
        //showAnim(new Swing());
        //dismissAnim(this, new ZoomOutExit());
        View inflate = View.inflate(mContext, R.layout.dialog_del_confirm, null);
        idTvDel = (TextView) inflate.findViewById(R.id.id_tv_del);
        idTvClose = (TextView) inflate.findViewById(R.id.id_tv_close);
        idImgClose = ((ImageView) inflate.findViewById(R.id.id_img_close));
        idEdtTypeName = ((TextView) inflate.findViewById(R.id.id_edt_type_name));
        idEdtTypeName.setText("请确认删除，删除后数据不可恢复？");
        //设置背景颜色，和背景的透明圆弧角度
        inflate.setBackgroundDrawable(
                CornerUtils.cornerDrawable(Color.parseColor("#f8f9fa"), dp2px(10)));

        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        idTvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        idTvDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initHttp();
            }
        });

    }

    private void initHttp() {
        HttpRequest.postUrl(Api.GUADAN_DEL_LABLE)
                .addParams("id",id)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(mContext, json);
                        if (checkCode){
                            simpleInterface.nothing();
                            dismiss();
                        }
                    }
                    @Override
                    public void onError(Exception e) {

                    }
                });
    }

}